<?php
include("../config.php");
include("./API.php");
tongji("mpz");
$token="".$mpz["token"]."";//社区的TokenID
$key = "".$mpz["key"]."";//社区的密匙
$qq=$_GET['qq'];//下单账号
$num=$_GET['num']?:'100';//下单数量
$gid=$_GET['gid']?:''.$mpz["gid"].'';//社区商品编号
$hh=$_GET["hh"]?:"\n";//换行符号(默认\n)
$time = time();
$skey=$_GET['key'];//你申请的key
$list=file_get_contents("./mpz/KEY/key_list.txt");
$result=preg_match_all("/『密钥：".$key."』『QQ：(.*?)』/",$list,$bb);
$bb0=$bb[2][0];
if(file_exists("./mpz/KEY/user/".$skey.".txt")){
$file=file("./mpz/KEY/user/".$skey.".txt");
$file=$file['0'];
$file=($file-$num);
if($file<0){
echo "".$web["ming"]."API名片赞下单".$hh."";
echo "━━━━━━━━━".$hh."";
echo "名片赞余额不足".$hh."";
echo "请你联系：".$bb0."进行充值额度！".$hh."";
echo "━━━━━━━━━".$hh."";
echo "Tips:".$web["ming"]."API技术支持";
}else{
$params = [
		'api_token' => $token,
		'timestamp' => $time,
		'gid' => $gid,
		'num' => $num,
		'value1' => $qq
		];
$sign = getSign($params, $key);
$arr = [
	'api_token' => $token,
	'timestamp' => $time,
	'sign' => $sign,
	'gid' => $gid,
	'num' => $num,
	'value1' => $qq
	];
$json=json_decode(curlPost(''.$mpz["domain"].'/api/order',$arr),true);
if($json['message']=="恭喜你，下单成功！"){
file_put_contents("./mpz/KEY/user/".$skey.".txt",$file);
echo "".$web["ming"]."API名片赞下单".$hh."";
echo "━━━━━━━━━".$hh."";
echo "[账号]：".$qq."".$hh."";
echo "[数量]：".$num."".$hh."";
echo "[余额]：".$file."个".$hh."";
echo "[速度]：因协议变更速度有变".$hh."";
echo "[订单号]：".$json["id"]."".$hh."";
echo "[提示]：请开启附近人点赞".$hh."";
echo "━━━━━━━━━".$hh."";
echo "Tips:".$web["ming"]."API技术支持";
}else{
echo "".$web["ming"]."API名片赞下单".$hh."";
echo "━━━━━━━━━".$hh."";
echo "".$json["message"]."".$hh."";
echo "━━━━━━━━━".$hh."";
echo "Tips:".$web["ming"]."API技术支持";
}
}
}else{
echo "".$web["ming"]."API名片赞下单".$hh."";
echo "━━━━━━━━━".$hh."";
echo "没有token请去查看API参数进行申请！".$hh."";
echo "必须真实QQ号注册".$hh."";
echo "━━━━━━━━━".$hh."";
echo "Tips:".$web["ming"]."API技术支持";
}
//举例：要传递的参数是：api_token=100×tamp=1531745059&gid=10001&action=test 则签名计算方式为：md5(action=test&api_token=100&gid=10001×tamp=1531745059用户密匙)

/**
* @param $param array 要签名的参数数组
* @param $key string 用户密匙
* @return string
*/
function getSign($param, $key){
	$signPars = "";
	ksort($param);
	foreach ($param as $k => $v) {
		if ($k != 'sign' && $v !== null) {
			$signPars .= $k."=".$v."&";
		}
	}
	$signPars = trim($signPars, '&');
	$signPars .= $key;
	$sign = md5($signPars);
	return $sign;
}

function curlPost($url,$data){
	$ch = curl_init();
	$params[CURLOPT_URL] = $url;    //请求url地址
	$params[CURLOPT_HEADER] = FALSE; //是否返回响应头信息
	$params[CURLOPT_SSL_VERIFYPEER] = false;
	$params[CURLOPT_SSL_VERIFYHOST] = false;
	$params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
	$params[CURLOPT_POST] = true;
	$params[CURLOPT_POSTFIELDS] = $data;
	curl_setopt_array($ch, $params); //传入curl参数
	$content = curl_exec($ch); //执行
	curl_close($ch); //关闭连接
	return $content;
}
?>